package com.dyrj.base.system.org.controller;
import com.dyrj.base.system.menu.service.MenuService;
import com.dyrj.base.system.org.model.TDepartment;
import com.dyrj.base.system.org.service.TDepartmentService;
import com.dyrj.common.BaseController;
import com.dyrj.vo.ResultMsg;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/system/org")
public class TDepartmentController extends BaseController {
    @Resource
    private TDepartmentService tDepartmentService;
    @Resource
    private MenuService menuService;
    /**
     * @Title: index
     * @Description: TODO(主页)
     * @return String    返回类型
     */
    @GetMapping("/index")
    @RequiresPermissions("system:org:index")
    public String index(ModelMap map) {
//        Integer tenantid =getTenantid();
        //是超级管理员时，不选择各租户组织机构
//        if("0".equals(getUserId())){
//            map.addAttribute("dept", "nodept");
//        }else{
//            map.addAttribute("dept", "dodept");
//        }
        Long tenantid = getTenantid();
        List list = tDepartmentService.selectAllTreeDept(tenantid);
        map.addAttribute("deptMenuTree", list);
        return "system/org/org";
    }
    @GetMapping("/table")
    @ResponseBody
    @RequiresPermissions("system:org:index")
    public ResultMsg table(TDepartment record) {
        return tDepartmentService.table(record);
    }
//    /**
//     * 列表
//     */
    @GetMapping("/treelist/{id}")
    @ResponseBody
    @RequiresPermissions("system:org:index")
    public List treelist(@PathVariable Long id) {
        TDepartment dept = tDepartmentService.info(id);
        return dept.getDeptVo();
    }
    @GetMapping("/treelist")
    @ResponseBody
    @RequiresPermissions("system:org:index")
    public List treelist() {
        Long tenantid = getTenantid();
        List list = tDepartmentService.selectAllTreeDept(tenantid);
        return list;
    }

    /**
     * @Title: add
     * @Description: TODO(新增)
     * @param record
     * @return ResultMsg    返回类型
     */
    @PostMapping("/")
    @ResponseBody
    @RequiresPermissions("system:org:index")
    public ResultMsg add(TDepartment record) {
        return tDepartmentService.add(record);
    }

    /**
     * @Title: info
     * @Description: TODO(详情)
     * @param id
     * @return SysRole    返回类型
     */
    @GetMapping("/{id}")
    @ResponseBody
    @RequiresPermissions("system:org:index")
    public TDepartment info(@PathVariable Long id) {
        return tDepartmentService.info(id);
    }

    /**
     * @Title: update
     * @Description: TODO(更新)
     * @param record
     * @return ResultMsg    返回类型
     */
    @PutMapping("/")
    @ResponseBody
    @RequiresPermissions("system:org:index")
    public ResultMsg update(TDepartment record) {
        return tDepartmentService.update(record);
    }

    /**
     * @Title: del
     * @Description: TODO(删除)
     * @param id
     * @return ResultMsg    返回类型
     */
    @DeleteMapping("del/{id}")
    @ResponseBody
    @RequiresPermissions("system:org:index")
    public ResultMsg del(@PathVariable Long id) {
        return tDepartmentService.del(id);
    }

}
